package com.woniuxy02;

import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-05-26 9:34
 */
public class Test04 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int random;
        int num;
        //统计游戏次数
        int count = 0;
        System.out.println("是否开始游戏y/n");
        String answer = sc.next();
        while ("y".equals(answer)) {
            System.out.println("开始游戏");
            random = (int) (Math.random() * 100);
            System.out.println("random:" + random);
            count=0;
            do {
                System.out.println("输入你猜到的数字");
                num = sc.nextInt();
                //猜一次计数
                count++;
                if (num != random) {
                    if (num > random) {
                        System.out.println("猜大了");
                    } else {
                        System.out.println("猜小了");
                    }
                    System.out.println("还剩下" + (5 - count) + "次机会");
                } else {
                    System.out.println("猜对了");
                    break;
                }

            } while (count < 5);
            System.out.println("本次游戏结束");
            System.out.println("是否继续游戏y/n");
            answer = sc.next();
        }
        System.out.println("游戏结束");

    }
}
